package io.renren.modules.app.controller;

import io.renren.common.utils.R;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.form.UserOrderForm;
import io.renren.modules.app.service.OrderSeervice;
import io.renren.modules.app.service.UserService;
import io.renren.modules.app.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

@RestController
@RequestMapping("/app/order")
@Api("订单业务接口")
public class OrderController {

    @Autowired
    private OrderSeervice orderSeervice;

    @Autowired
    private JwtUtils jwtUtils;
    @Autowired
    private UserService userService;



    @Login
    @PostMapping("/searchUserOrderList")
    @ApiOperation("用户订单查询")
    public R searchUser0rderList(@RequestBody UserOrderForm form, @RequestHeader HashMap header){
        //ValidatorUtils.validateEntity(form);
        String token=header.get("token").toString();
        int userId=Integer.parseInt(jwtUtils.getClaimByToken(token).getSubject());
        int page=form.getPage();
        int length=form.getLength() ;
        int start=(page-1)*length;
        HashMap map=new HashMap();
        map.put("userId",userId);
        map.put("start",start);
        map.put("length",length);
        ArrayList<HashMap> list=orderSeervice.searchuserorderlist(map);
        return R.ok().put("list",list);
    }

}
